package com.classroompie.classroompieserver.controller;

import com.classroompie.classroompiecommon.result.Result;
import com.classroompie.classroompiepojo.request.AddUserInput;
import com.classroompie.classroompiepojo.request.UserLoginInput;
import com.classroompie.classroompiepojo.response.LoginVO;
import com.classroompie.classroompieserver.service.UserService;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;


/**
 * @author jiahao
 * @since 2024/6/20 周四
 */
@RestController
@RequestMapping("/user")
@CrossOrigin("*")
public class UserController {
    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @PostMapping()
    public Result addUser(@RequestBody @Valid AddUserInput addUserInput) {
        userService.addUser(addUserInput);
        return Result.success();
    }

    @PostMapping("/login")
    public Result<LoginVO> login(@RequestBody @Valid UserLoginInput userLoginInput) {
        LoginVO loginVO =  userService.login(userLoginInput);
        return Result.success(loginVO);
    }

    @PostMapping("/course/{code}")
    public Result<Object> joinCourse(@PathVariable String code) {
        userService.addCourse(code);
        return Result.success();
    }

    @GetMapping("/course/top")
    public Result<Object> getTopCourse() {
        return Result.success(userService.getTopCourse());
    }

    @GetMapping("/course/teach")
    public Result<Object> getTeachCourse() {
        return Result.success(userService.getTeachCourse());
    }

    @GetMapping("/course/learn")
    public Result<Object> getLearnCourse() {
        return Result.success(userService.getLearnCourse());
    }

    @GetMapping("/course/archive")
    public Result<Object> getArchiveCourse() {
        return Result.success(userService.getArchiveCourse());
    }

}
